home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / jpsrc2.zip / JCMASTER.C < prev    next >
C/C++ Source or Header  |  1991-10-03  |  4KB  |  128 lines

  1. /*
  2.  * jcmaster.c
  3.  *
  4.  * Copyright (C) 1991, Thomas G. Lane.
  5.  * This file is part of the Independent JPEG Group's software.
  6.  * For conditions of distribution and use, see the accompanying README file.
  7.  *
  8.  * This file contains the main control for the JPEG compressor.
  9.  * The system-dependent (user interface) code should call jpeg_compress()
  10.  * after doing appropriate setup of the compress_info_struct parameter.
  11.  */
  12.  
  13. #include "jinclude.h"
  14.  
  15.  
  16. METHODDEF void
  17. c_per_scan_method_selection (compress_info_ptr cinfo)
  18. /* Central point for per-scan method selection */
  19. {
  20.   /* Edge expansion */
  21.   jselexpand(cinfo);
  22.   /* Subsampling of pixels */
  23.   jselsubsample(cinfo);
  24.   /* MCU extraction */
  25.   jselcmcu(cinfo);
  26. }
  27.  
  28.  
  29. LOCAL void
  30. c_initial_method_selection (compress_info_ptr cinfo)
  31. /* Central point for initial method selection */
  32. {
  33.   /* Input image reading method selection is already done. */
  34.   /* So is output file header formatting (both are done by user interface). */
  35.  
  36.   /* Gamma and color space conversion */
  37.   jselccolor(cinfo);
  38.   /* Entropy encoding: either Huffman or arithmetic coding. */
  39. #ifdef ARITH_CODING_SUPPORTED
  40.   jselcarithmetic(cinfo);
  41. #else
  42.   cinfo->arith_code = FALSE;    /* force Huffman mode */
  43. #endif
  44.   jselchuffman(cinfo);
  45.   /* Pipeline control */
  46.   jselcpipeline(cinfo);
  47.   /* Overall control (that's me!) */
  48.   cinfo->methods->c_per_scan_method_selection = c_per_scan_method_selection;
  49. }
  50.  
  51.  
  52. LOCAL void
  53. initial_setup (compress_info_ptr cinfo)
  54. /* Do computations that are needed before initial method selection */
  55. {
  56.   short ci;
  57.   jpeg_component_info *compptr;
  58.  
  59.   /* Compute maximum sampling factors; check factor validity */
  60.   cinfo->max_h_samp_factor = 1;
  61.   cinfo->max_v_samp_factor = 1;
  62.   for (ci = 0; ci < cinfo->num_components; ci++) {
  63.     compptr = &cinfo->comp_info[ci];
  64.     if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  65.     compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  66.       ERREXIT(cinfo->emethods, "Bogus sampling factors");
  67.     cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  68.                    compptr->h_samp_factor);
  69.     cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  70.                    compptr->v_samp_factor);
  71.  
  72.   }
  73.  
  74.   /* Compute logical subsampled dimensions of components */
  75.   for (ci = 0; ci < cinfo->num_components; ci++) {
  76.     compptr = &cinfo->comp_info[ci];
  77.     compptr->true_comp_width = (cinfo->image_width * compptr->h_samp_factor
  78.                 + cinfo->max_h_samp_factor - 1)
  79.                 / cinfo->max_h_samp_factor;
  80.     compptr->true_comp_height = (cinfo->image_height * compptr->v_samp_factor
  81.                  + cinfo->max_v_samp_factor - 1)
  82.                  / cinfo->max_v_samp_factor;
  83.   }
  84. }
  85.  
  86.  
  87. /*
  88.  * This is the main entry point to the JPEG compressor.
  89.  */
  90.  
  91.  
  92. GLOBAL void
  93. jpeg_compress (compress_info_ptr cinfo)
  94. {
  95.   /* Read the input file header: determine image size & component count.
  96.    * NOTE: the user interface must have initialized the input_init method
  97.    * pointer (eg, by calling jselrppm) before calling me.
  98.    * The other file reading methods (get_input_row etc.) were probably
  99.    * set at the same time, but could be set up by input_init itself,
  100.    * or by c_ui_method_selection.
  101.    */
  102.   (*cinfo->methods->input_init) (cinfo);
  103.  
  104.   /* Give UI a chance to adjust compression parameters and select */
  105.   /* output file format based on results of input_init. */
  106.   (*cinfo->methods->c_ui_method_selection) (cinfo);
  107.  
  108.   /* Now select methods for compression steps. */
  109.   initial_setup(cinfo);
  110.   c_initial_method_selection(cinfo);
  111.  
  112.   /* Initialize the output file & other modules as needed */
  113.   /* (entropy_encoder is inited by pipeline controller) */
  114.  
  115.   (*cinfo->methods->colorin_init) (cinfo);
  116.   (*cinfo->methods->write_file_header) (cinfo);
  117.  
  118.   /* And let the pipeline controller do the rest. */
  119.   (*cinfo->methods->c_pipeline_controller) (cinfo);
  120.  
  121.   /* Finish output file, release working storage, etc */
  122.   (*cinfo->methods->write_file_trailer) (cinfo);
  123.   (*cinfo->methods->colorin_term) (cinfo);
  124.   (*cinfo->methods->input_term) (cinfo);
  125.  
  126.   /* My, that was easy, wasn't it? */
  127. }
  128.